package org.huang.rocketmq.demo.broadcast;

import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.common.message.Message;
import org.apache.rocketmq.remoting.common.RemotingHelper;
import org.huang.rocketmq.demo.Constant;

/**
 * 广播消息提供者，跟普通的一样。主要是把消息发送到rocketmq 的 broker上面。
 */
public class BroadcastProducer {
    public static void main(String[] args) throws Exception {
        DefaultMQProducer producer = new DefaultMQProducer("BroadcastProducer");
        producer.setNamesrvAddr(Constant.NAME_SERVER_ADDR);
        producer.start();

        for (int i = 0; i < 10; i++) {
            Message msg = new Message("BroadcastTopicTest",
                    "TagA",
                    ("Broadcast Message" + i).getBytes(RemotingHelper.DEFAULT_CHARSET));
            SendResult sendResult = producer.send(msg);
            System.out.printf("%s%n", sendResult);
        }
        producer.shutdown();
    }
}